first task <<
Previous Next >> Task2
second task
def stu2a(account):
if account == "40823107":
return account + "-2"
elif account[0:3] == "407":
return "s" + account
else:
return account
teamb = []
# open file, default is read mode, since txt content no chinese char
# no encoding = "UTF-8" is needed
with open("stage3_2a.txt") as fh:
# readlines will read into the whole line and put into list format
# has \n at the end of each line
data = fh.readlines()
#print(len(data))
for i in range(len(data)):
group = data[i].rstrip("\n").split("\t")
teamb.append(group)
output = ""
seperator = "-"*10 + "<br />"
for i in teamb[0:]:
team = i[0]
leader = stu2a(i[1])
m1 = stu2a(i[3])
m2 = stu2a(i[5])
m3 = stu2a(i[7])
m4 = stu2a(i[9])
m5 = stu2a(i[11])
m6 = stu2a(i[13])
try:
m7 = stu2a(i[15])
except:
m7 = ""
try:
m8 = stu2a(i[17])
except:
m8 = ""
leaderrepo = "<a href='http://github.com/" + leader + "/cd2021'>" + leader + " repo</a>"
leadersite = "<a href='http://" + leader + ".github.io/cd2021'>" + leader + " site</a>"
m1repo = "<a href='http://github.com/" + m1 + "/cd2021'>" + m1 + " repo</a>"
m1site = "<a href='http://" + m1 + ".github.io/cd2021'>" + m1 + " site</a>"
m2repo = "<a href='http://github.com/" + m2 + "/cd2021'>" + m2 + " repo</a>"
m2site = "<a href='http://" + m2 + ".github.io/cd2021'>" + m2 + " site</a>"
m3repo = "<a href='http://github.com/" + m3 + "/cd2021'>" + m3 + " repo</a>"
m3site = "<a href='http://" + m3 + ".github.io/cd2021'>" + m3 + " site</a>"
m4repo = "<a href='http://github.com/" + m4 + "/cd2021'>" + m4 + " repo</a>"
m4site = "<a href='http://" + m4 + ".github.io/cd2021'>" + m4 + " site</a>"
m5repo = "<a href='http://github.com/" + m5 + "/cd2021'>" + m5 + " repo</a>"
m5site = "<a href='http://" + m5 + ".github.io/cd2021'>" + m5 + " site</a>"
m6repo = "<a href='http://github.com/" + m6 + "/cd2021'>" + m6 + " repo</a>"
m6site = "<a href='http://" + m6 + ".github.io/cd2021'>" + m6 + " site</a>"
leaderteamrepo = "<a href='http://github.com/" + leader + "/" + team + "'>" + team + " repo</a>"
leaderteamsite = "<a href='http://" + leader + ".github.io/" + team + "'>" + team + " site</a>"
m1teamrepo = "<a href='http://github.com/" + m1 + "/" + team + "'>" + team + " repo</a>"
m1teamsite = "<a href='http://" + m1 + ".github.io/" + team + "'>" + team + " site</a>"
m2teamrepo = "<a href='http://github.com/" + m2 + "/" + team + "'>" + team + " repo</a>"
m2teamsite = "<a href='http://" + m2 + ".github.io/" + team + "'>" + team + " site</a>"
m3teamrepo = "<a href='http://github.com/" + m3 + "/" + team + "'>" + team + " repo</a>"
m3teamsite = "<a href='http://" + m3 + ".github.io/" + team + "'>" + team + " site</a>"
m4teamrepo = "<a href='http://github.com/" + m4 + "/" + team + "'>" + team + " repo</a>"
m4teamsite = "<a href='http://" + m4 + ".github.io/" + team + "'>" + team + " site</a>"
m5teamrepo = "<a href='http://github.com/" + m5 + "/" + team + "'>" + team + " repo</a>"
m5teamsite = "<a href='http://" + m5 + ".github.io/" + team + "'>" + team + " site</a>"
m6teamrepo = "<a href='http://github.com/" + m6 + "/" + team + "'>" + team + " repo</a>"
m6teamsite = "<a href='http://" + m6 + ".github.io/" + team + "'>" + team + " site</a>"
output += leaderrepo + " | " + leadersite + " | " +leaderteamrepo + " | " + leaderteamsite + " | " +m1repo + " | " + m1site + " | " + m1teamrepo + " | " + m1teamsite + " | " +m2repo + " | " + m2site + " | " + m2teamrepo + " | " + m2teamsite + " | " +m3repo + " | " + m3site + " | " + m3teamrepo + " | " + m3teamsite + " | " +m4repo + " | " + m4site + " | " + m4teamrepo + " | " + m4teamsite + " | " +m5repo + " | " + m5site + " | " + m5teamrepo + " | " + m5teamsite + " | " +m6repo + " | " + m6site + " | " + m6teamrepo + " | " + m6teamsite
if m7 != "":
m7repo = "<a href='http://github.com/" + m7 + "/cd2021'>" + m7 + " repo</a>"
m7site = "<a href='http://" + m7 + ".github.io/cd2021'>" + m7 + " site</a>"
m7teamrepo = "<a href='http://github.com/" + m7 + "/" + team + "'>" + team + " repo</a>"
m7teamsite = "<a href='http://" + m7 + ".github.io/" + team + "'>" + team + " site</a>"
output += " | " + m7repo + "| " + m7site + " | " + m7teamrepo + " | " + m7teamsite
else:
output += ""
if m8 != "":
m8repo = "<a href='http://github.com/" + m8 + "/cd2021'>" + m8 + " repo</a>"
m8site = "<a href='http://" + m8 + ".github.io/cd2021'>" + m8 + " site</a>"
m8teamrepo = "<a href='http://github.com/" + m8 + "/" + team + "'>" + team + " repo</a>"
m8teamsite = "<a href='http://" + m8 + ".github.io/" + team + "'>" + team + " site</a>"
output += " | " + m8repo + "| " + m8site + " | " + m8teamrepo + " | " + m8teamsite + "<br />" + seperator
else:
output += "<br />" + seperator
print(output)
# the following will use group data to generate needed html
程式結果
40823131 repo | 40823131 site | stage3_ag1 repo | stage3_ag1 site | 40823112 repo | 40823112 site | stage3_ag1 repo | stage3_ag1 site | 40823123 repo | 40823123 site | stage3_ag1 repo | stage3_ag1 site | 40823145 repo | 40823145 site | stage3_ag1 repo | stage3_ag1 site | 40823136 repo | 40823136 site | stage3_ag1 repo | stage3_ag1 site | 40823109 repo | 40823109 site | stage3_ag1 repo | stage3_ag1 site | 40823116 repo | 40823116 site | stage3_ag1 repo | stage3_ag1 site | 40823108 repo| 40823108 site | stage3_ag1 repo | stage3_ag1 site
----------
40823151 repo | 40823151 site | stage3_ag2 repo | stage3_ag2 site | 40623121 repo | 40623121 site | stage3_ag2 repo | stage3_ag2 site | 40871106 repo | 40871106 site | stage3_ag2 repo | stage3_ag2 site | 40823102 repo | 40823102 site | stage3_ag2 repo | stage3_ag2 site | 40823104 repo | 40823104 site | stage3_ag2 repo | stage3_ag2 site | 40823106 repo | 40823106 site | stage3_ag2 repo | stage3_ag2 site | 40823101 repo | 40823101 site | stage3_ag2 repo | stage3_ag2 site | 40823132 repo| 40823132 site | stage3_ag2 repo | stage3_ag2 site
----------
40823119 repo | 40823119 site | stage3_ag3 repo | stage3_ag3 site | 40823150 repo | 40823150 site | stage3_ag3 repo | stage3_ag3 site | 40823103 repo | 40823103 site | stage3_ag3 repo | stage3_ag3 site | 40823107-2 repo | 40823107-2 site | stage3_ag3 repo | stage3_ag3 site | 40523252 repo | 40523252 site | stage3_ag3 repo | stage3_ag3 site | 40823154 repo | 40823154 site | stage3_ag3 repo | stage3_ag3 site | repo | site | stage3_ag3 repo | stage3_ag3 site
----------
40823142 repo | 40823142 site | stage3_ag4 repo | stage3_ag4 site | 40823144 repo | 40823144 site | stage3_ag4 repo | stage3_ag4 site | 40823127 repo | 40823127 site | stage3_ag4 repo | stage3_ag4 site | 40823148 repo | 40823148 site | stage3_ag4 repo | stage3_ag4 site | 40823121 repo | 40823121 site | stage3_ag4 repo | stage3_ag4 site | 40823135 repo | 40823135 site | stage3_ag4 repo | stage3_ag4 site | 40823114 repo | 40823114 site | stage3_ag4 repo | stage3_ag4 site | 40823146 repo| 40823146 site | stage3_ag4 repo | stage3_ag4 site
----------
40823111 repo | 40823111 site | stage3_ag5 repo | stage3_ag5 site | 40823115 repo | 40823115 site | stage3_ag5 repo | stage3_ag5 site | 40823128 repo | 40823128 site | stage3_ag5 repo | stage3_ag5 site | 40823120 repo | 40823120 site | stage3_ag5 repo | stage3_ag5 site | 40823140 repo | 40823140 site | stage3_ag5 repo | stage3_ag5 site | 40823124 repo | 40823124 site | stage3_ag5 repo | stage3_ag5 site | 40823139 repo | 40823139 site | stage3_ag5 repo | stage3_ag5 site | 40823126 repo| 40823126 site | stage3_ag5 repo | stage3_ag5 site
----------
40823152 repo | 40823152 site | stage3_ag6 repo | stage3_ag6 site | 40823110 repo | 40823110 site | stage3_ag6 repo | stage3_ag6 site | 40823122 repo | 40823122 site | stage3_ag6 repo | stage3_ag6 site | 40823125 repo | 40823125 site | stage3_ag6 repo | stage3_ag6 site | 40823117 repo | 40823117 site | stage3_ag6 repo | stage3_ag6 site | 40823129 repo | 40823129 site | stage3_ag6 repo | stage3_ag6 site | 40823149 repo | 40823149 site | stage3_ag6 repo | stage3_ag6 site | 40823153 repo| 40823153 site | stage3_ag6 repo | stage3_ag6 site
----------
video
first task <<
Previous Next >> Task2